﻿import QtQuick 2.11
import QtQuick.Window 2.3
import QtQuick.Dialogs 1.2

import com.leamus.gamedata 1.0

import "."
import "_Global"
import "_Global/Popup"
import "_Global/Button"

import "_Global/Global.js" as GlobalJS
import "GameJS.js" as GameJS

Window {

    //signal s_StartGame(int playerCount, int cID, int lID, int restart)


    function $showGameServerInfo() {
        //console.debug("-----------")
    }

    //初始化，游戏启动时由 C++ Manager 调用
    function initOnce() {

        //与C++信号绑定
        GameManager.s_OverGame.connect(function(ret) {_private.overGame(ret);});
        GameManager.s_StartGame.connect(function() {

            //gameClass.visible = false;
            gameUI.visible = true;
            gameUI.focus = true;

        });


        GameManager.s_qml_JoinGroup.connect(function(gID) {
            gameInGroup.item.nGroupID = gID;
            gameInGroup.item.clearMsg();
            gameInGroup.visible = true;
            gameInGroup.focus = true;
        });

        GameManager.s_qml_OthersJoinGroup.connect(function(nickName,bIn) {
            if(bIn == true)
                gameInGroup.item.appendText(nickName + " 加入房间");
            else
                gameInGroup.item.appendText(nickName + " 离开房间");
        });
        GameManager.s_qml_OthersReadyInGroup.connect(function(nickName,status,duiWu) {
            if(status == 2)
                gameInGroup.item.appendText(nickName + " 准备,队伍:" + duiWu);
            else if(status == 1)
                gameInGroup.item.appendText(nickName + " 取消准备");
            else
                gameInGroup.item.appendText(nickName + " 干了个啥ERROR?" + status);
        });

        //聊天
        GameManager.s_qml_OthersMessage.connect(function(type,seatID,message) {
            switch(type) {
            case 1:
                gameUI.item.showPlayerMsg(seatID,message);
                break;
            default:
                console.error("s_qml_OthersMessage type ERROR!", type);
            }
        });


        GameManager.s_qml_ChangeAllWindowVisible.connect(_private.changeAllWindowVisible);

        GameManager.s_qml_DebugMsg.connect(debugWindow.item.showDebugMsg);

        GameManager.s_qml_UpdateInfo.connect(function(url, type) {
            var tMsg = qsTr("<a href='%1'><h2>有新版本，点此升级</h2></a>").arg(url);

            switch(type) {
            case -1:
                var tErrorMsg = qsTr("<a href='%1'><h2>版本检测出错，请退出或点此升级后重试</h2></a>").arg(url);
                gameMsgBoxVersion.text = tErrorMsg;
                gameMsgBoxVersion.showMsg(false,true);

                console.error("s_qml_UpdateInfo type ERROR:", url, type);
                break;
            case 0:
                //gameMsgBoxVersion.text = msg;
                //gameMsgBoxVersion.showMsg(true,false);
                //login.item.enableLogin();
                login.item.serverResponseMsg("");

                console.debug("s_qml_UpdateInfo", url, type);
                break;
            case 1:
                gameMsgBoxVersion.text = tMsg;
                gameMsgBoxVersion.showMsg(true,false);
                login.item.serverResponseMsg("");

                console.debug("s_qml_UpdateInfo", url, type);
                break;
            case 2:
                gameMsgBoxVersion.text = tMsg;
                gameMsgBoxVersion.showMsg(false,true);

                console.debug("s_qml_UpdateInfo", url, type);
                break;
            default:
                gameMsgBoxVersion.text = tMsg;
                gameMsgBoxVersion.showMsg(false,true);

                console.error("s_qml_UpdateInfo type ERROR:", url, type);
            }
        });

        GameManager.s_qml_Message.connect(function(msg, type) {
            switch(type) {
            case 0:
                gameMsgBox.text = msg;
                gameMsgBox.showMsg(true,false);
                console.debug("s_qml_Message", msg, type);
                break;
            case 1:
                gameMsgBox.text = msg;
                gameMsgBox.showMsg(true,true);
                console.debug("s_qml_Message", msg, type);
                break;
            case 2:
                gameMsgBox.text = msg;
                gameMsgBox.showMsg(false,true);
                console.debug("s_qml_Message", msg,type);
                break;
            default:
                gameMsgBox.text = msg;
                gameMsgBox.showMsg(false,true);
                console.error("s_qml_Message type Error!", msg, type);
            }
        });



        UserInfo.s_RefreshAllLevels.connect(function(){gameClass.item.refreshAllLevels();});

        UserInfo.s_RefreshRanking.connect(function(code){});

        UserInfo.s_RefreshItems.connect(function(code){
            if(gameClass.item.levelInfo.bShowBuyingResult) {    //如果需要提示
                switch(code) {
                case 0:
                    var msg = "";
                    if(UserInfo.itemsInfo.flagCorrectAnswer)
                        msg += "学习卡 ";
                    if(UserInfo.itemsInfo.canReview)
                        msg += "复习卡 ";
                    messageBox.showMessage("以下卡片已激活：" + msg);
                    break;
                default:
                    messageBox.showMessage("购买道具错误ERROR");
                }
                gameClass.item.levelInfo.bShowBuyingResult = false;
            }
        });

        UserInfo.s_loginStatus.connect(function(code) {   //用户登录后,创建并载入level信息,并刷新
            //console.log("login status:")
            switch(code) {
            case 0:
                login.visible = false;
                //login.focus = false;
                //login.item.hide()
                register.visible = false;
                gameSchool.visible = false;
                serverChoiceWindow.visible = true;
                serverChoiceWindow.focus = true;

                //if(Global.config.fullScreen)root.showFullScreen();
                //else root.showMaximized();

                break;
            case 1: //没有此用户
                login.item.serverResponseMsg("用户名或密码错误");
                break;
            case 2: //密码错误
                login.item.serverResponseMsg("用户名或密码错误");
                break;
            default:
                login.item.serverResponseMsg("登录出错ERROR");
            }
        });

        UserInfo.s_regStatus.connect(function(code) {   //用户注册
            //console.log("reg status:")
            switch(code) {
            case 0:
                login.visible = true;
                login.focus = true;
                register.visible = false;
                break;
            case 1:
                register.item.showErr("名称已被注册");
                break;
            default:
                register.item.showErr("注册出错ERROR");
            }

            //gameClass.item.createLevels(1)
        });

        UserInfo.s_choiceGameServerStatus.connect(function(code) {   //用户选择服务器后
            //console.debug("登录服务器code:",code)
            if(code == 0) { //选择服务器完毕,并且不需要注册游戏名
                //login.visible = false
                //register.visible = false
                serverChoiceWindow.visible = false;

                regGameUserInfoWindow.visible = false;
                regGameUserInfoWindow.source = "";

                var levelInfo = UserInfo.sl_getUserLevelInfo(GameManager.userInfo.scoreCount);
                Global.userInfo.userLevel = levelInfo.level;
                Global.userInfo.userLevelName = levelInfo.name;

                gameSchool.visible = true;
                gameSchool.focus = true;
            }
            else if(code == 1) {    //需要注册游戏名
                serverChoiceWindow.visible = false;

                regGameUserInfoWindow.source = "RegGameUserInfo.qml"
                regGameUserInfoWindow.visible = true;
                regGameUserInfoWindow.focus = true;
            }
            else {
                console.error("ChoiceGameServerStatus ERROR!");
            }

        });

        UserInfo.s_regGameStatus.connect(function(code) {   //用户注册游戏名状态
            //console.log("regGame status:");
            switch(code) {
            case 1:
                regGameUserInfoWindow.item.showErr("名称已被注册");
                break;
            case 2:
                regGameUserInfoWindow.item.showErr("长度必须在4到16个字母、数字或汉字之间（1个汉字占2个长度）");
                break;
            case 3:
                regGameUserInfoWindow.item.showErr("名称中含有禁词");
                break;
            default:
                console.error("RegGameStatus ERROR!");
            }

            //gameClass.item.createLevels(1)
        });



        GameCore.s_InitOnce.connect(function(nPokeMaxCount,nPlayerMaxCount) {
            gameUI.item.initOnce(nPokeMaxCount,nPlayerMaxCount);
        });





        //s_StartGame.connect(GameManager.sl_qml_SinglePlay);



        //root.minimumWidth = Screen.desktopAvailableWidth;
        //root.minimumHeight = Screen.desktopAvailableHeight;
        //root.maximumWidth = root.minimumWidth = Global.gamePos.sizeWindow.width
        //root.maximumHeight = root.minimumHeight = Global.gamePos.sizeWindow.height
        //console.log("size:",Global)

        //root.show();
        //login.item.raise();

        //if(Global.config.fullScreen)
        //    root.showFullScreen();
        //else
        //    root.showMaximized();

        //msgBox.appendText("深林孤鹰出<font size=20 color=red>杀</font><br>")
        //msgBox.appendText("资治通鉴出<font size=20 color=blue>闪</font><br>")
        //GameCore.temp_Init(5,0)


        console.log("!initOnce over!");
    }


    id: root
    width: Screen.desktopAvailableWidth
    height: Screen.desktopAvailableHeight
    visible: true
    title: Global.config.strWindowTitle
    //color: "transparent"
    color: "#00000000"
    flags: flags | Qt.FramelessWindowHint   // | Qt.Widget
    //flags: Qt.SubWindow | Qt.Tool | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint | Qt.WindowStaysOnTopHint
    contentOrientation: Qt.PrimaryOrientation
                        //Qt.PrimaryOrientation   //使用显示设备的首选方向。
                        //Qt.LandscapeOrientation，横屏。
                        //Qt.PortraitOrientation，竖屏。
                        //Qt.InvertedLandscapeOrientation，相对于横屏模式，旋转了180°。
                        //Qt.InvertedPortraitOrientation，相对于竖屏模式，旋转了180°。

    Item {
        id: rootItem
        anchors.fill: parent
        //focus: true

        //登录窗口
        Loader {
            id: login
            source: "Login/login.qml"
            anchors.fill: parent
            z: 100
            focus: true

            Connections {
                target: login.item

                onS_reg: {
                    //login.visible = false;
                    //register.visible = true;
                    //register.focus = true;
                    Qt.openUrlExternally(Global.config.urlRegisterUser);
                }
                onS_forgot: {
                    Qt.openUrlExternally(Global.config.urlForgot);
                }
                onS_minimized: {
                    root.visibility = Window.Minimized;
                }
                onS_login: {
                    GameManager.userInfo.sl_qml_UserLogin(param);
                }
            }
        }

        //注册窗口
        Loader {
            id: register
            source: "Register/Register.qml"
            anchors.fill: parent
            visible: false
            z: 100

            Connections {
                target: register.item
                onS_RegUser: {
                    GameManager.userInfo.sl_qml_UserReg(param);
                }
                onS_Close: {
                    register.visible = false;
                    login.visible = true;
                    login.focus = true;
                }
            }
        }

        //选择服务器窗口
        Loader {
            id: serverChoiceWindow
            source: "ServerChoice.qml"
            anchors.fill: parent
            visible: false
            z: 100

            Connections {
                target: serverChoiceWindow.item
                onS_ChoiceServer: {
                    serverChoiceWindow.item.setServerButtons(false);
                    GameManager.userInfo.sl_qml_ChoiceGameServer(gameServerID);
                }
            }
        }

        //注册游戏名窗口
        Loader {
            id: regGameUserInfoWindow
            //source: "RegGameUserInfo.qml"
            anchors.fill: parent
            visible: false
            z: 100

            Connections {
                target: regGameUserInfoWindow.item
                onS_RegGameUserInfo: {
                    GameManager.userInfo.sl_qml_GameUserReg(param);
                    //s_RegGameUserInfo(param)
                }
            }
        }

        //学校窗口
        Loader {
            id: gameSchool
            source: "GameSchool/GameSchool.qml"
            anchors.fill: parent
            visible: false
            z: 200

            Connections {
                target: gameSchool.item
                onS_myDocument: {
                }
                onS_studing: {
                    gameStudyType.visible = true;
                    gameStudyType.focus = true;
                    gameSchool.visible = false;
                }
                onS_Group: {
                    gameGroup.visible = true;
                    gameGroup.focus = true;
                    gameSchool.visible = false;
                }
                onS_ranking: {
                    gameRanking.item.refreshRanking();
                    gameRanking.visible = true;
                    gameRanking.focus = true;
                }
                onS_market: {
                }
                onS_showGameUserInfo: {
                    gameUserInfo.item.refreshInfo();
                    gameUserInfo.visible = true;
                }
                onShowConfig: {
                    menuConfig.show();
                }
            }
        }

        //信息窗口
        Loader {
            id: gameUserInfo
            source: "GameUserInfo.qml"
            anchors.centerIn: parent
            width: Global.gamePos.mapGameUserInfo.rectBack.width
            height: Global.gamePos.mapGameUserInfo.rectBack.height
            visible: false
            z: 300

            Connections {
                target: gameUserInfo.item
                onS_close: {
                    gameUserInfo.visible = false;
                }
            }

            /*
            Component {
                id: compGameUserInfo
                GameUserInfo {
                    onS_close: {
                        gameUserInfo.visible = false;
                    }
                }
            }*/
        }

        //排名窗口
        Loader {
            id: gameRanking
            source: "GameRanking.qml"
            anchors.centerIn: parent
            width: Global.dpW(1756)
            height: Global.dpH(1000)
            visible: false
            z: 300

            Connections {
                target: gameRanking.item
                onS_close: {
                    gameRanking.visible = false;
                }
            }

            /*
            Component {
                id: compGameUserInfo
                GameUserInfo {
                    onS_close: {
                        gameUserInfo.visible = false;
                    }
                }
            }*/
        }

        //竞技游戏窗口
        Loader {
            id: gameGroup
            source: "Group/Group.qml"
            anchors.fill: parent
            visible: false
            z: 350

            Connections {
                target: gameGroup.item
                onS_CreateGroup: {
                    GameManager.sl_qml_CreateGroup(maxPlayerCount,password,classID);
                }
                onS_JoinGroup: {
                    GameManager.sl_qml_JoinGroup(gID, pass);
                }

                onS_Close: {
                    gameSchool.visible = true;
                    gameSchool.focus = true;
                    gameGroup.visible = false;
                }
                onShowConfig: {
                    menuConfig.show();
                }
            }
        }

        //竞技游戏房间窗口
        Loader {
            id: gameInGroup
            source: "Group/InGroup.qml"
            anchors.fill: parent
            visible: false
            z: 351

            Connections {
                target: gameInGroup.item
                onS_GameReady: {
                    GameManager.sl_qml_GetReady(duiWu);
                }
                onS_StartGame: {
                    GameManager.sl_qml_StartGame();
                }
                onS_ExitGroup: {
                    GameManager.sl_qml_ExitGroup();
                    gameGroup.visible = true;
                    gameGroup.focus = true;
                    gameInGroup.visible = false;
                }
                onShowConfig: {
                    menuConfig.show();
                }

            }
        }

        //选择模式(汉译英,英译汉)界面
        Loader {
            id: gameStudyType
            source: "GameStudyType.qml"
            anchors.fill: parent
            visible: false
            z: 400

            Connections {
                target: gameStudyType.item
                onS_choiceType: {
                    //gameSchool.visible = false
                    gameGrade.nStudyType = typeID;
                    GameManager.sl_qml_ChangeStudyType(typeID);

                    gameStudyType.visible = false;

                    //gameGrade.item.refreshLevelsFromClassID(classId)
                    gameGrade.visible = true;
                    gameGrade.focus = true;
                }

                onS_close: {
                    gameStudyType.visible = false;
                    gameSchool.visible = true;
                    gameSchool.focus = true;
                }
                onShowConfig: {
                    menuConfig.show();
                }
            }
        }

        //选择年级(初中,高中,四六级)界面
        Loader {
            property int nStudyType: 0
            id: gameGrade
            source: "GameGrade.qml"
            anchors.fill: parent
            visible: false
            z: 400

            Connections {
                target: gameGrade.item
                onS_choiceClass: {
                    //gameSchool.visible = false
                    var tClassID;
                    switch(gameGrade.nStudyType) {
                    case 1:
                        tClassID = classId;
                        break;
                    case 2:
                        tClassID = classId + 8;
                        break;
                    default:
                        break;
                    }
                    gameGrade.visible = false;

                    gameClass.item.refreshLevelsFromClassID(tClassID);
                    gameClass.visible = true;
                    gameClass.focus = true;
                }

                onS_close: {
                    gameGrade.visible = false;
                    gameStudyType.visible = true;
                    gameStudyType.focus = true;
                }
                onShowConfig: {
                    menuConfig.show();
                }
            }
        }


        //选择等级窗口
        Loader {
            id: gameClass
            source: "GameClass.qml"
            anchors.fill: parent
            visible: false
            z: 500

            Connections {
                target: gameClass.item
                onS_StartGame: {
                    gameUI.nCID = cID;
                    gameUI.nLID = lID;
                    _private.startGame(cID,lID,restart);
                }
                onS_close: {
                    gameClass.visible = false;
                    gameGrade.visible = true;
                    gameGrade.focus = true;
                }
                onShowConfig: {
                    menuConfig.show();
                }
            }

            Component.onCompleted: {
            }
        }

        //游戏界面
        Loader {
            property int nCID   //重新开始 时使用的ID
            property int nLID

            id: gameUI
            source: "GameUI.qml"
            anchors.fill: parent
            visible: false
            //focus: true
            z: 600

            Connections {
                target: gameUI.item

                onS_restartGame: _private.startGame(gameUI.nCID,gameUI.nLID,code)

                onS_closeGameUI: {
                    gameUI.visible = false;
                    //gameClass.visible = true
                }
                onS_debugMsg: debugWindow.item.showDebugMsg(msg);

                onS_sendMessage: GameManager.sl_qml_SendMessage(msg, 1);
            }
        }

        GameConfigMenu {
            id: menuConfig
            anchors.centerIn: parent
            z: 700
            showMask: true
            maskParent: parent
            maskColor: 'lightgrey'
            maskOpacity: 0.5

        }



        //信息框
        Popup {
            function showMessage(msg) {
                textMessage.text = msg;
                messageBox.show();
            }

            id: messageBox
            innerWidth: Global.gamePos.dialogMap.rectBack.width
            innerHeight: Global.gamePos.dialogMap.rectBack.height
            z: 900
            color: "#00FFFFFF"
            visible: false
            enabled: true
            //animationType: "fade";
            //easingType: Easing.Linear
            duration: 200

            anchors.centerIn: parent

            showMask: false
            maskParent: parent
            maskColor: "black"
            maskOpacity: 0.3

            Image {
                source: Global._FixResourcePath_R("Media/Images/Class/ClassInfo/Back.png")
                anchors.fill: parent
            }

            Text {
                id: textMessage
                x: Global.gamePos.dialogMap.rectTextMsg.x
                y: Global.gamePos.dialogMap.rectTextMsg.y
                width: Global.gamePos.dialogMap.rectTextMsg.width
                height: Global.gamePos.dialogMap.rectTextMsg.height
                font.pixelSize: Global.gamePos.dialogMap.nTextMsgFontSize
                //font.family: ""
                font.bold: true
                color: "white"
                //style: Text.Outline;
                //styleColor: "black"
                //horizontalAlignment: Text.AlignHCenter
                //verticalAlignment: Text.AlignVCenter
                //horizontalAlignment: Text.AlignLeft

                wrapMode: Text.Wrap
                //lineHeight: 1.3

            }

            ImageButton2 {
                id: buttonClose        //关闭
                x: Global.gamePos.dialogMap.rectClose.x
                y: Global.gamePos.dialogMap.rectClose.y
                width: Global.gamePos.dialogMap.rectClose.width
                height: Global.gamePos.dialogMap.rectClose.height

                source: Global._FixResourcePath_R("Media/Images/Class/ClassInfo/Close.png")

                soundEffectClick: Global.resource.effects.effectButton
                bEffectOn: Global.config.bEffectOn

                onButtonClicked: {
                    messageBox.close();
                }
            }
        }


        GameMsgBox {
            id: gameMsgBox
            z: 901

            width: Global.gamePos.dialogMap.rectBack.width
            height: Global.gamePos.dialogMap.rectBack.height
            visible: false
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter

        }

        GameMsgBox {
            id: gameMsgBoxVersion
            z: 902

            width: Global.gamePos.dialogMap.rectBack.width
            height: Global.gamePos.dialogMap.rectBack.height
            visible: false
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter

        }







        //调试窗口
        Loader {
            id: debugWindow
            source: "DebugWindow.qml"
            anchors.fill: parent
            visible: false
            z: 800

            Connections {
                target: debugWindow.item

                onDebugGameManager: GameManager.sl_qml_DebugButton(value,param)
                onDebugGameCore: GameCore.sl_qml_DebugButton(type,v)
                onDebugGameUI: gameUI.item.debugGameWindow(value,param)
                onDebugGameWindow: {
                    switch(value) {
                    case 1: //试玩
                        _private.nPlayerCount = param;
                        login.visible = false;
                        //login.item.hide()
                        gameClass.visible = false;
                        gameUI.visible = true;
                        gameUI.focus = true;
                        GameManager.sl_qml_SinglePlay(param,1,1,true);

                        //console.debug("ok")
                        break;
                    default:
                        console.log(value, param);
                        break;
                    }
                }
            }
        }

        Rectangle {
            y: 0
            z: 900
            width: Global.dpW(50)
            height: Global.dpH(20)
            anchors.right: parent.right
            //color: "#00000000"
            opacity: 0.01
            visible: GameManager.platform == "debug" ? true : false

            Text {
                text: qsTr("调试")
            }
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    if(debugWindow.visible == false) {
                        debugWindow.visible = true;
                    }
                    else {
                        debugWindow.visible = false;
                    }
                    //console.debug(debugWindow.visible)
                }
            }
        }


        Keys.onEscapePressed:  {
            event.accepted = true;
            _private.exitBox();
        }
    }


    MessageDialog {
        id: msgBox
        text: ""
        title: "深林孤鹰警告你"
        visible: false
    }

    /*
    Rectangle {
        color: "red"
        width: 50
        height: 50
        MouseArea {

            anchors.fill: parent
            onClicked: {
                console.debug("窗口:",root.activeFocusItem,rootItem);
            }
        }

    }*/

    QtObject {  //私有数据,函数,对象等
        id: _private
        property int nPlayerCount: 2    //玩家个数

        //游戏开始，GameCore信号
        function startGame(cID,lID,restart) {
            //s_StartGame(nPlayerCount,cID,lID,restart)
            GameManager.sl_StartGame(nPlayerCount,cID,lID,restart);
        }

        //游戏结束,Manager数据处理完毕后,再调用显示
        function overGame(ret) {
            gameUI.item.overGame(ret);
            //gameClass.item.refreshAllLevels();
            //gameUI.focus = false;
            //gameClass.item.refreshClass(gameClass.item.nClassID, gameClass.item.nCurrentLevelID);
        }

        function windowSizeChanged() {
            //var t1 = root.width / Global.gamePos.sizeWindow.width
            //var t2 = root.height / Global.gamePos.sizeWindow.height
            //if(t1 > t2)
            //    t1 = t2

            //itemScale.scale = t1

            //Global.multiplierX = root.width / Global.gamePos.posWindow.x;
            //Global.multiplierY = root.height / Global.gamePos.posWindow.y;
            Global.multiplierW = root.width / Global.gamePos.sizeWindow.width;
            Global.multiplierH = root.height / Global.gamePos.sizeWindow.height;


            if(gameUI.item != null) {
                gameUI.item.refreshAllPokesPosition(2);
                gameUI.item.setPlayersPos();
            }
        }

        //退出框
        function exitBox() {
            //如果游戏在进行,则显示退出本局游戏
            if(GameCore.gameStatus == GameClass.Game_Status_Continue)
                gameUI.item.changeGameEscMenuVisible();
            else {  //否则显示退出游戏
                if(menuConfig.visible)
                {
                    menuConfig.hide();
                    rootItem.focus = true;
                }
                else
                {
                    menuConfig.show();
                    menuConfig.focus = true;
                }
            }
        }


        //改变所有窗口visible
        //type:1(退出到登录界面);2(退出到服务器选择界面)
        function changeAllWindowVisible(type) {
            switch(type) {
            case 1:
                serverChoiceWindow.item.setServerButtons(true);

                register.visible = false;
                serverChoiceWindow.visible = false;
                regGameUserInfoWindow.visible = false;
                gameSchool.visible = false;
                gameUserInfo.visible = false;
                gameRanking.visible = false;
                gameGroup.visible = false;
                gameInGroup.visible = false;
                gameStudyType.visible = false;
                gameGrade.visible = false;
                gameClass.visible = false;
                //gameUI.visible = false;

                login.visible = true;
                login.focus = true;
                //debugWindow.visible = false;
                break;
            case 2:
                serverChoiceWindow.item.setServerButtons(true);

                login.visible = false;
                register.visible = false;
                regGameUserInfoWindow.visible = false;
                gameSchool.visible = false;
                gameUserInfo.visible = false;
                gameRanking.visible = false;
                gameGroup.visible = false;
                gameInGroup.visible = false;
                gameStudyType.visible = false;
                gameGrade.visible = false;
                gameClass.visible = false;
                //gameUI.visible = false;

                serverChoiceWindow.visible = true;
                serverChoiceWindow.focus = true;
                //debugWindow.visible = false;

                break;
            }
        }
    /*
        function windowSizeChanged1() {
            //if(height < width * 768 / 1024)
                //height = width * 768 / 1024;
            Global.gamePos.sizeWindow.height = gameWindow.height

            //if(width <= height * 1024 / 768)
                //width = height * 1024 / 768;
            //console.debug(itemScale.x,itemScale.y)
            //console.debug(gameWindow.x,gameWindow.y)
            Global.gamePos.sizeWindow.width = gameWindow.width

            setPlayersPos(playerCount)
            refreshAllPokesPosition(2)
        }*/


    }



    onWidthChanged: {
        //console.debug(Math.floor(width * 3 / 4), height)
        //if(Math.abs(Math.floor(width * Global.gamePos.sizeWindow.height / Global.gamePos.sizeWindow.width) - height) > 1) {
        //    height = Math.floor(width * Global.gamePos.sizeWindow.height / Global.gamePos.sizeWindow.width)
            //console.debug("width change")
        //}
        _private.windowSizeChanged();
    }
    onHeightChanged: {
        //console.debug(Math.floor(height / 3 * 4), width)
        //if(Math.abs(Math.floor(height / Global.gamePos.sizeWindow.height * Global.gamePos.sizeWindow.width) - width) > 1) {
        //    width = Math.floor(height / Global.gamePos.sizeWindow.height * Global.gamePos.sizeWindow.width)
            //console.debug("height change")
        //}
        _private.windowSizeChanged();
    }



    onClosing: {
        //console.debug("窗口:",root.activeFocusItem,root.active);
        close.accepted = false;    //窗口关闭信息:false表示不接受
        _private.exitBox();
    }
/*
    Keys.onEscapePressed:  {
        event.accepted = true;
        _private.exitBox();
    }*/

    Component.onCompleted: {
        //root.debugMsg.connect(gameUI.item.debugMsg)
        //root.debugGame.connect(gameUI.item.debugGame)


        console.log("OS:", Qt.platform.os);
        console.log("QML工作路径:", Global._FixLocalPath_R("."));
        console.log("Qt三个对象环境:",GameManager,GameCore,UserInfo);

//其他变量测试:

        //类 的 枚举
        console.debug("PokeClass._ObjType:",(PokeClass._ObjType));           //undefined
        console.debug("PokeClass.Type_Button:",(PokeClass.Type_Button));     //8

        console.debug("PokeClass._Flags:",(PokeClass._Flags));           //undefined
        console.debug("PokeClass.Flag_Enable:",(PokeClass.Flag_Enable));  //2
        //console.debug("GameCore.Game_Button_Giveup:",GameCoreGame_Button_Giveup)  //Error!

        console.debug("GameClass._GameButtonValue:",(GameClass._GameButtonValue)); //undefined
        console.debug("GameClass.Game_Button_Giveup:",(GameClass.Game_Button_Giveup));  //2

        console.debug("GameClass._GameStatus:",(GameClass._GameStatus)); //undefined
        console.debug("GameClass.Game_Status_Terminated:",(GameClass.Game_Status_Terminated));  //3

        console.debug("WuJiangClass.Value_HanMeiMei:",WuJiangClass.Value_HanMeiMei);   //1

        //对象 的 属性
        console.debug("GameCore.wuJiangList:",GameCore.wuJiangList,GameCore.wuJiangList.length); //YES!8
        console.debug("GameCore.gameStatus:",GameCore.gameStatus);   //1
        console.debug("GameManager.gameConfig:",GameManager.gameConfig,Object.keys(GameManager.gameConfig),GameManager.gameConfig["ServerIP"]);

        console.debug("UserInfo.gameStatus:",UserInfo.gameStatus);   //QVariant
        console.debug("GameManager.platform:",GameManager.platform); //debug



        if(Global.config.fullScreen)
            root.showFullScreen();
        else
            root.showMaximized();




        //console.debug("Game_Playing:",Game_Playing)
        //console.debug("_ClientGameStatus:",_ClientGameStatus.Game_Playing)
        //console.debug("_ClientGameStatus:",GameManagerClass.Game_Playing)
        /*
        var v1,v2

        v1 = compPoke.createObject(gameWindow,{"nFlags": PokeClass.Flag_Null});
        v2 = compPlayer.createObject(gameWindow,{"nFlags": PokeClass.Flag_Null});

        v1.pokeSource = "Pai101.jpg";
        v1.nFlags = PokeClass.Flag_Show | PokeClass.Flag_Enable | PokeClass.Flag_ZhengMian
        //v1.visible = true;
        v1.x = 0
        v1.y = 0
        //v1.z = 100

        v2.source = "Player/erzhang.png";
        //arrayPlayer[i].nFlags = PokeClass.Flag_Null;
        v2.visible = true;
        v2.x = 100
        v2.y = 0
        */
        //v2.z = 100
        console.log("!QML组件初始化完毕");
    }
}
